package com.jysz.certificate.persistence.model.mf;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.jysz.certificate.persistence.enums.mf.BillStatus;
import com.jysz.certificate.persistence.model.pm.PAShopMonthDetail;
import com.jysz.certificate.persistence.model.system.Financial;
import com.jysz.certificate.persistence.model.system.Shop;
import com.jysz.certificate.persistence.model.system.Treaty;
import com.jysz.webcore.ssh.entity.AbstractBaseEntity;

/**
 * 发票费用项
 * @author xuxiaolong
 */
@Entity
@Table(name = "mf_bill_option_")
@org.hibernate.annotations.Entity
public class BillOption extends AbstractBaseEntity<Long> {

	private static final long serialVersionUID = 8857266275898346934L;
	
	/** 发票*/
	private List<Bill> bills;
	
	/** 金融机构*/
	private Financial financial;
	
	/** 协议*/
	private Treaty treaty;
	
	/** 销售店*/
	private Shop shop;
	
	/** 月份 2013-01的形式*/
	private String month;
	
	/** 金额*/
	private Double amount;
	
	/** 是否为预收*/
	private Boolean advance;
	
	/** 状态*/
	private BillStatus status;
	
	/** 实收日期*/
	private Date incomeDate;
	
	/** 备注*/
	private String remark;

	/** 组标识(季度、半年)*/
	private String group;
	
	/** 挪动到的Option ID*/
	private Long moveId;
	
	private Boolean hasAssigned; //是否已分配绩效
	
	private PAShopMonthDetail paShopMonthDetail;
	
	/** 驻店员名字*/
	private String defendName;
	/** 区域经理名字*/
	private String managerName;
	/** 释放数*/
	private Integer quantity;
	/** 本月入库*/
	private Integer moneyStock;
	/** 上月结存*/
	private Integer moneyRemain;
	
	/** 操作 :
	 * 0为可编辑, 应收或者新建预收
	 * 1为不可编辑,金额被挪动到其他月份,只做展示 
	 * 2为不可编辑, 已经被前几个月预收(在其它发票单中)*/
	private Integer operate;
	/** 是否小于系统生成的金额－用于绩效
	 * １代表小于。
	 * */
	private Integer lessThan;
	public BillOption(){}
	public BillOption(Treaty treaty,Shop shop,Financial financial,String month,Double amount,Boolean advance,String remark,String defendName,String managerName,Integer quantity,Integer moneyStock,Integer moneyRemain){
		/*List<Bill> l=new ArrayList<Bill>();
		l.add(bill);
		this.bills=l;*/
		this.financial=financial;
		this.shop=shop;
		this.month=month;
		this.amount=amount;
		this.advance=advance;
		this.remark=remark;
		this.operate=0;
		this.treaty = treaty;
		this.status=BillStatus.TEMPSAVE;
		this.defendName = defendName;
		this.managerName = managerName;
		this.quantity = quantity;
		this.lessThan=0;
		this.moneyStock = moneyStock;
		this.moneyRemain = moneyRemain;
	}
	@ManyToOne(targetEntity=Shop.class,cascade=CascadeType.REFRESH)
	@JoinColumn(name="_shop_id", insertable=true, updatable=true,columnDefinition="bigint(20)") 
	public Shop getShop() {
		return shop;
	}
	public void setShop(Shop shop) {
		this.shop = shop;
	}

	@ManyToOne(targetEntity=Financial.class,cascade=CascadeType.REFRESH)
	@JoinColumn(name="_financial_id", insertable=true, updatable=true,columnDefinition="bigint(20)")
	public Financial getFinancial() {
		return financial;
	}

	public void setFinancial(Financial financial) {
		this.financial = financial;
	}
	
	@Column(name = "_month", nullable = false,columnDefinition="varchar(255)")
	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	@Column(name = "_amount", nullable = false,columnDefinition="numeric(8,2)")
	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	@Column(name = "_remark", nullable = true,columnDefinition="varchar(255)")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "_advance", nullable = true,columnDefinition="bit(1)")
	public Boolean getAdvance() {
		return advance;
	}

	public void setAdvance(Boolean advance) {
		this.advance = advance;
	}
	
	@Column(name = "_operate", nullable = true,columnDefinition="int(11)")
	public Integer getOperate() {
		return operate;
	}
	public void setOperate(Integer operate) {
		this.operate = operate;
	}
	
	@Column(name = "_status", nullable = false,columnDefinition="int(11)")
	public BillStatus getStatus() {
		return status;
	}
	public void setStatus(BillStatus status) {
		this.status = status;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rs_mf_bill_option_", joinColumns = @JoinColumn(name = "_option_id"), inverseJoinColumns = @JoinColumn(name = "_bill_id"))
	public List<Bill> getBills() {
		return bills;
	}
	public void setBills(List<Bill> bills) {
		this.bills = bills;
	}
	public void setBillsForOne(Bill bill) {
		List<Bill> l=new ArrayList<Bill>();
		l.add(bill);
		this.bills=l;
	}
	
	@Column(name = "_income_date", nullable = true)
	public Date getIncomeDate() {
		return incomeDate;
	}
	public void setIncomeDate(Date incomeDate) {
		this.incomeDate = incomeDate;
	}
	
	@Column(name = "_move_id", nullable = true,columnDefinition="bigint(20)")
	public Long getMoveId() {
		return moveId;
	}
	public void setMoveId(Long moveId) {
		this.moveId = moveId;
	}

	public boolean equals(Object obj){
		BillOption b=(BillOption) obj;
		if(this.getId()==b.getId())
			return true;
		return false;
	}
	
	@Column(name = "_has_assigned", nullable = true)
	public Boolean getHasAssigned() {
		return hasAssigned;
	}
	public void setHasAssigned(Boolean hasAssigned) {
		this.hasAssigned = hasAssigned;
	}
	
	@ManyToOne(targetEntity = PAShopMonthDetail.class, cascade=CascadeType.REFRESH)
	@JoinColumn(name="_pa_shop_month_detail_id", insertable=true, updatable=true) 
	public PAShopMonthDetail getPaShopMonthDetail() {
		return paShopMonthDetail;
	}
	public void setPaShopMonthDetail(
			PAShopMonthDetail paShopMonthDetail) {
		this.paShopMonthDetail = paShopMonthDetail;
	}
	@Column(name = "_defend_name", nullable = true,columnDefinition="varchar(255)")
	public String getDefendName() {
		return defendName;
	}
	public void setDefendName(String defendName) {
		this.defendName = defendName;
	}
	@Column(name = "_manager_name", nullable = true,columnDefinition="varchar(255)")
	public String getManagerName() {
		return managerName;
	}
	public void setManagerName(String managerName) {
		this.managerName = managerName;
	}
	@Column(name = "_quantity", nullable = true,columnDefinition="int(11)")
	public Integer getQuantity() {
		return quantity;
	}
	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}
	
	@Column(name = "_less_than", nullable = false,columnDefinition="int(1)")
	public Integer getLessThan() {
		return lessThan;
	}
	public void setLessThan(Integer lessThan) {
		this.lessThan = lessThan;
	}
	@ManyToOne(targetEntity=Treaty.class,cascade=CascadeType.REFRESH)
	@JoinColumn(name="_trtaey_id", insertable=true, updatable=true,columnDefinition="bigint(20)") 
	public Treaty getTreaty() {
		return treaty;
	}
	public void setTreaty(Treaty treaty) {
		this.treaty = treaty;
	}
	@Column(name = "_moneyStock", nullable = true,columnDefinition="int(11)")
	public Integer getMoneyStock() {
		return moneyStock;
	}
	public void setMoneyStock(Integer moneyStock) {
		this.moneyStock = moneyStock;
	}
	@Column(name = "_moneyRemain", nullable = true,columnDefinition="int(11)")
	public Integer getMoneyRemain() {
		return moneyRemain;
	}
	public void setMoneyRemain(Integer moneyRemain) {
		this.moneyRemain = moneyRemain;
	}
	@Column(name = "_group", nullable = true,columnDefinition="varchar(40)")
	public String getGroup() {
		return group;
	}
	public void setGroup(String group) {
		this.group = group;
	}
	
	
}
